package com.ruoyi.stock2.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stock2.domain.FasttextTrain;
import com.ruoyi.stock2.service.IFasttextTrainService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 准备训练集Controller
 * 
 * @author ruoyi
 * @date 2021-08-17
 */
@Controller
@RequestMapping("/stock2/train")
public class FasttextTrainController extends BaseController
{
    private String prefix = "stock2/train";

    @Autowired
    private IFasttextTrainService fasttextTrainService;

    @RequiresPermissions("stock2:train:view")
    @GetMapping()
    public String train()
    {
        return prefix + "/train";
    }

    /**
     * 查询准备训练集列表
     */
    @RequiresPermissions("stock2:train:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FasttextTrain fasttextTrain)
    {
        startPage();
        List<FasttextTrain> list = fasttextTrainService.selectFasttextTrainList(fasttextTrain);
        return getDataTable(list);
    }

    /**
     * 导出准备训练集列表
     */
    @RequiresPermissions("stock2:train:export")
    @Log(title = "准备训练集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FasttextTrain fasttextTrain)
    {
        List<FasttextTrain> list = fasttextTrainService.selectFasttextTrainList(fasttextTrain);
        ExcelUtil<FasttextTrain> util = new ExcelUtil<FasttextTrain>(FasttextTrain.class);
        return util.exportExcel(list, "train");
    }

    /**
     * 新增准备训练集
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存准备训练集
     */
    @RequiresPermissions("stock2:train:add")
    @Log(title = "准备训练集", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FasttextTrain fasttextTrain)
    {
        return toAjax(fasttextTrainService.insertFasttextTrain(fasttextTrain));
    }

    /**
     * 修改准备训练集
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FasttextTrain fasttextTrain = fasttextTrainService.selectFasttextTrainById(id);
        mmap.put("fasttextTrain", fasttextTrain);
        return prefix + "/edit";
    }

    /**
     * 修改保存准备训练集
     */
    @RequiresPermissions("stock2:train:edit")
    @Log(title = "准备训练集", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FasttextTrain fasttextTrain)
    {
        return toAjax(fasttextTrainService.updateFasttextTrain(fasttextTrain));
    }

    /**
     * 删除准备训练集
     */
    @RequiresPermissions("stock2:train:remove")
    @Log(title = "准备训练集", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fasttextTrainService.deleteFasttextTrainByIds(ids));
    }
}
